package org.fas.ui
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.fas.event.PicLoadEvent;
	import org.fas.net.FLoader;
	import org.fas.utils.FuDisplayer;

	public class FImage extends Sprite
	{
		protected var src_r:String;
		public var isLoading:Boolean = false;
		protected var loader:FLoader = new FLoader();
		public function FImage(_src:String="",_x:Number=0,_y:Number=0)
		{
			super();
			this.x = _x;
			this.y = _y;
			if(_src!=""){
				src = _src;
			}
		}
		public function set src(_src:String):void{
			if(isLoading){
				loader.unload();
			}
			if(_src!=""){
				if(src_r!=_src){
					isLoading = true;
					src_r = _src;
					loader.loadIn(_src,this.onComplete);
				}else{
					onComplete();
				}
			}
		}
		public function get src():String{
			return src_r;
		}
		protected function onComplete(_content:Bitmap=null):void{
			isLoading = false;
			if(_content!=null){
				FuDisplayer.removeAllIn(this);
				this.addChild(_content);
			}
			this.dispatchEvent(new Event(Event.COMPLETE));
			//loader.removeEventListener(Event.COMPLETE,onComplete);
		}
	}
}